<?php

namespace app\admin\controller;


use app\admin\model\Config;
use app\admin\model\Drawing;
use app\admin\model\DrawingBank;
use app\admin\model\Substation;

/**
 * 图纸管理控制器
 * Class Drawings
 * @package app\admin\controller
 */
class Drawings extends Base
{

    //接口图纸列表
    public function getApiImg(){
        $keyword = input("keyword/s");
        if (input('?table')) {//是否表格请求
            $ImgApiData = config("ImgApiData");
            $result = file_get_contents(url($ImgApiData["ApiList"]["imgList"], [
                'token' => md5(md5($ImgApiData["key"]).date("Y-m-d")),
                'limit' => $this->after_limit,
                'page' => $this->after_page,
                'keyword'  =>  $keyword
            ], true, $ImgApiData["domain"]));
            $result = json_decode($result,true);
            $result["code"] = 0;
            return json($result);
        }
        return view('getApiImg',[
            'title'         =>  '接口图纸列表',
        ]);
    }

    //添加接口库图纸
    public function addDrawingBankOld(){
        set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去
        $data = input("post.");
        $DrawingBank = new DrawingBank();
        $msg = $DrawingBank->checkData($data, [
            ["draw_id", "require", "接口图纸id不能为空"],
            ["no", "require", "接口图纸id不能为空"],
            ["no2", "require", "接口图纸id不能为空"],
        ]);
        if ($msg === true) {
            if($DrawingBank->checkDrawOnly($data['draw_id'])){
                $result["code"] = 1;
                $result["msg"] = '接口图纸id已存在';
            }else {
                //配置参数检测添加,修改为本数据库数据值
                $data = $DrawingBank->drawingBankConfigAddNew([0=>$data]);
                $data = $this->setDrawingAtlas($data);//下载图集
                $data = $data[0];//单一添加需取出值
                if ($DrawingBank->mySave($data,'drawing_bank_id')) {
                    $result["code"] = 0;
                    $result["msg"] = "操作成功!";
                } else {
                    $result["code"] = 10000;
                    $result["msg"] = "操作失败!";
                }
            }
        }else {
            $result["code"] = 1;
            $result["msg"] = $msg;
        }
        return json($result);
    }

    //添加接口库图纸---新
    public function addDrawingBank(){
        set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去
        $data = input("post.");
        $Drawing = new Drawing();
        $msg = $Drawing->checkData($data, [
            ["draw_id", "require", "接口图纸id不能为空"],
            ["no", "require", "接口图纸id不能为空"],
            ["no2", "require", "接口图纸id不能为空"],
        ]);
        if ($msg === true) {
            if($Drawing->checkDrawOnly($data['draw_id'])){
                $result["code"] = 1;
                $result["msg"] = '接口图纸id已存在';
            }else {
                //配置参数检测添加,修改为本数据库数据值
                $data = $Drawing->drawingBankConfigAddNew([0=>$data]);
                $data = $this->setDrawingAtlas($data);//下载图集
                $data = $data[0];//单一添加需取出值
                if ($Drawing->mySave($data,'drawing_id')) {
                    $result["code"] = 0;
                    $result["msg"] = "操作成功!";
                } else {
                    $result["code"] = 10000;
                    $result["msg"] = "操作失败!";
                }
            }
        }else {
            $result["code"] = 1;
            $result["msg"] = $msg;
        }
        return json($result);
    }

    //添加多个接口库图纸
    public function addAllDrawingBankOld(){
        set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去
        $data = input("post.data/a");
        $sum = count($data);
        $DrawingBank = new DrawingBank();
        $count = 0;//剔除个数
        foreach ($data as $key=>$val){
            $msg = $DrawingBank->checkData($val, [
                ["draw_id", "require", "接口图纸id不能为空"],
                ["no", "require", "接口图纸id不能为空"],
                ["no2", "require", "接口图纸id不能为空"],
            ]);
            //去掉不符合条件和已存在的
            if($msg !== true || $DrawingBank->checkDrawOnly($val['draw_id'])){
                unset($data[$key]);
                $count++;
                continue;//结束本次循环
            }
        }
        //配置参数检测添加,修改为本数据库数据值
        $data = $DrawingBank->drawingBankConfigAddNew($data);
        $data = $this->setDrawingAtlas($data);//下载图集
        if ($DrawingBank->mySaveAll($data)) {
            $result["code"] = 0;
            $result["msg"] = "操作成功,添加成功（".($sum - $count)."）个！";
        } else {
            $result["code"] = 10000;
            $result["msg"] = "操作失败!";
        }
        return json($result);
    }

    //添加多个接口库图纸
    public function addAllDrawingBank(){
        set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去
        $data = input("post.data/a");
        $sum = count($data);
        $Drawing = new Drawing();
        $count = 0;//剔除个数
        foreach ($data as $key=>$val){
            $msg = $Drawing->checkData($val, [
                ["draw_id", "require", "接口图纸id不能为空"],
                ["no", "require", "接口图纸id不能为空"],
                ["no2", "require", "接口图纸id不能为空"],
            ]);
            //去掉不符合条件和已存在的
            if($msg !== true || $Drawing->checkDrawOnly($val['draw_id'])){
                unset($data[$key]);
                $count++;
                continue;//结束本次循环
            }
        }
        //配置参数检测添加,修改为本数据库数据值
        $data = $Drawing->drawingBankConfigAddNew($data);
        $data = $this->setDrawingAtlas($data);//下载图集
        if ($Drawing->mySaveAll($data)) {
            $result["code"] = 0;
            $result["msg"] = "操作成功,添加成功（".($sum - $count)."）个！";
        } else {
            $result["code"] = 10000;
            $result["msg"] = "操作失败!";
        }
        return json($result);
    }

    //更新图纸
    public function updateAllDrawingBank(){
        set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去
        $data = input("post.data/a");
        $Drawing = new Drawing();
        foreach ($data as $key=>$val){
            $msg = $Drawing->checkData($val, [
                ["draw_id", "require", "接口图纸id不能为空"],
                ["no", "require", "接口图纸id不能为空"],
                ["no2", "require", "接口图纸id不能为空"],
            ]);
            //去掉不符合条件和已存在的
            if($msg === true && $Drawing->checkDrawOnly($val['draw_id'])){
                //去掉不跟新字段
                unset($data[$key]["text_content"]);
            }else{
                unset($data[$key]);
                continue;//结束本次循环
            }
        }
        //配置参数检测添加,修改为本数据库数据值
        $data = $Drawing->drawingBankConfigAddNew($data);
        $data = $this->setDrawingAtlas($data);//下载图集
        $sCount = $Drawing->updateAllDrawingBank($data);
        if ($sCount > 0) {
            $result["code"] = 0;
            $result["msg"] = "操作成功,图纸更新（".$sCount."）个！";
        } else {
            $result["code"] = 10000;
            $result["msg"] = "操作失败!";
        }
        return json($result);
    }

    //获取图集
    private function setDrawingAtlas($data){
        $Config = new Config();
        $FileOperation = new FileOperation();
        $ImgApiData = config("ImgApiData");//获取配置
        foreach ($data as $DataKey=>$DataValues) {//循环数组
            //下载封面图
            if(!empty($DataValues['cover'])){
                //下载封面缩略图到服务器
                $fileResult = $FileOperation->downloadFile($ImgApiData['domain'].config("thumbnail").$DataValues['cover'],"",config("drawingBankFileDefaultDir").$DataValues["no"]."_".$DataValues["no2"].config("thumbnail")."/");
                if($fileResult['state']){
                    $data[$DataKey]['cover'] = "/".$fileResult['SaveName'];
                }else{
                    $data[$DataKey]['cover'] = "";
                }
            }
            $drawing_atlas = [];//新数组设置
            if (!empty($DataValues["drawing_atlas"])) {
                foreach ($DataValues["drawing_atlas"] as $key => $val) {
                    $config_id = $Config->getConfigId($val["config_name"]);//获取新的config_id
                    $drawing_atlas[$config_id]["title"] = $val["config_name"];//设置title名称
                    $drawing_atlas[$config_id]["data"][$key]["name"] = $val["name"];//设置文件名称
                    //下载图集
                    $fileResult = $FileOperation->downloadFile($ImgApiData['domain'] . $val['url'], "", config("drawingBankFileDefaultDir").$DataValues["no"]."_".$DataValues["no2"].config("atlas")."/");
                    $url = "";//设置新的地址
                    if ($fileResult['state']) {
                        $url = "/" . $fileResult['SaveName'];
                    }
                    //网站图片不处理
                    $image = \think\Image::open(".".$url);
                    if($image->width() > 750) {
                        //下载图片不为空处理图片
                        if (!empty($url)) {
                            \think\Config::load(APP_PATH . 'extra/upload.php');//加载上传配置文件
                            $UploadFileConfig = \think\Config::get("UploadFileConfig");//获取配置
                            $FileOperation->handleImg("." . $url, [$UploadFileConfig["DrawingAtlas"]["width"], $UploadFileConfig["DrawingAtlas"]["height"]], true);
                        }
                    }
                    $drawing_atlas[$config_id]["data"][$key]["url"] = $url;
                }
            }
            $data[$DataKey]["drawing_atlas"] = json_encode($drawing_atlas);//设置json格式返回
        }
        return $data;
    }

    //图纸库列表
    public function drawingBankList(){
        $DrawingConfigurationParameter = config("DrawingConfigurationParameter");
        $keyword = input('keyword');//关键字
        $cate = input('cate/d');//类型
        $layct = input('layct');//楼层
        $DrawingBank = new DrawingBank();
        $Config = new Config();
        $count = $DrawingBank->drawingBankListCount($keyword,$cate,$layct);
        if (input('?table')) {//是否表格请求
            $result['data'] = $DrawingBank->drawingBankList($keyword,$cate,$layct);
            $result['count'] = ceil($count / $this->after_limit);
            return json($result);
        }
        return view('drawingBankList',[
            'keyword'   => $keyword,
            'count'     => $count,
            'cate'      => $cate,
            'cateList'  => $Config->getConfigTypeList($DrawingConfigurationParameter['cate']),
            'layct'     => $layct,
            'title'     =>  '图纸库管理',
        ]);
    }

    //删除库图纸
    public function drawingBankDel(){
        $drawing_bank_id = input("drawing_bank_id/d",0);
        $DrawingBank = new DrawingBank();
        if(!empty($drawing_bank_id)){
            if($DrawingBank->del("drawing_bank_id",$drawing_bank_id,true)){
                $result["code"] = 0;
                $result["msg"] = "操作成功!";
                $result["url"] = url("Drawings/drawingBankList");
            }else{
                $result["code"] = 10000;
                $result["msg"] = "操作失败！";
            }
        }else{
            $result["code"] = 1;
            $result["msg"] = "drawing_bank_id参数为空!";
        }
        return json($result);
    }

    //同步接口图纸配置
    public function getDrawingConfig(){
        $ImgApiData = config("ImgApiData");
        $result = file_get_contents(url($ImgApiData["ApiList"]["getConfigList"], [
            'token' => md5(md5($ImgApiData["key"]).date("Y-m-d")),
        ], true, $ImgApiData["domain"]));
        $result = json_decode($result,true);
        $Config = new Config();
        foreach ($result["data"] as $key=>$val){
            $Config->drawingApiConfigAdd($key,$val);
        }
        $result["code"] = 0;
        $result["msg"] = "操作成功!";
        return json($result);
    }

    //发布库图纸
    public function releaseDrawing(){
        $drawing_bank_id = input("drawing_bank_id/d",0);
        if(!empty($drawing_bank_id)) {
            if(request()->isPost()){//发布图纸
                $data = input("post.");
                $Drawing = new Drawing();
                $msg = $Drawing->checkData($data,[
                    ["drawing_bank_id", "require", "库图纸ID不能为空"],
                    ["no", "require", "图纸编号不能为空"],
                    ["no2", "require", "图纸方案不能为空"],
                    ["topic", "require", "图纸标题不能为空"],
                    ["cover", "require", "图纸封面不能为空"],
                    ["price", "require", "图纸价格不能为空"],
                    ["struct", "require", "图纸框架架构不能为空"],
                    ["style", "require", "图纸风格不能为空"],
                    ["layct", "require", "图纸层数不能为空"],
                    ["text_content", "require", "图纸正文内容不能为空"],
                    ["substation_id", "require", "请选择发布网站"],
                ]);
                if ($msg === true) {
                    if($Drawing->checkFieldOnly("topic",$data["topic"],"drawing_id",0)){
                        $result["code"] = 1;
                        $result["msg"] = "图纸标题已存在";
                    }else{
                        if($Drawing->checkNO($data["no"],$data["no2"])){
                            $result["code"] = 1;
                            $result["msg"] = "该编号的图纸已存在改方案！";
                        }else{
                            if($Drawing->checkSave(0,$data["substation_id"])) {
                                $data["drawing_atlas"] = !empty($data["drawing_atlas"]) ? json_encode($data["drawing_atlas"]) : json_encode([]);//奇葩TP，类型装换没生效手动转化
                                if ($Drawing->mySave($data, "drawing_id", 0)) {
                                    //移动图纸文件
                                    $this->drawingFileMovement($Drawing->getLastInsID());
                                    $result["code"] = 0;
                                    $result["msg"] = "操作成功!";
                                } else {
                                    $result["code"] = 10000;
                                    $result["msg"] = "操作失败！";
                                }
                            }else{
                                $result["code"] = 20000;
                                $result["msg"] = "没有权限操作！";
                            }
                        }
                    }
                }else{
                    $result["code"] = 1;
                    $result["msg"] = $msg;
                }
            }else{//发布之前准备
                $DrawingBank = new DrawingBank();
                $dataInfo = $DrawingBank->dataInfo("drawing_bank_id",$drawing_bank_id);//获取库图纸信息
                //获取属性特殊处理
                $dataInfo["attrs_arr"] = StrToArray($dataInfo["attrs"]);
                $this->assign("dataInfo", $dataInfo);
                $Config = new Config();
                //循环获取图纸配置
                foreach (config("DrawingConfigurationParameter") as $key=>$val){
                    $this->assign($val, $Config->getConfigTypeList($val));
                }
                $this->assign("DrawingAtlasClassification", $Config->getConfigTypeList("DrawingAtlasClassification"));
                $Substation = new Substation();//分站类
                $userSubstationList = $Substation->userList();//获取分站集合
                $this->assign('userSubstationList',$userSubstationList);
            }
        }else{
            $result["code"] = 1;
            $result["msg"] = "drawing_bank_id，参数为空！";
        }
        return !empty($result) ? json($result) : view('releaseDrawing',[
            'title'     =>  '发布库图纸',
            'RadioIs'   =>  config("IsNoRadio"),//获取Radio配置
            'ueditor'   =>  true,
        ]);
    }

    //图纸列表
    public function drawingList(){
        $DrawingConfigurationParameter = config("DrawingConfigurationParameter");
        $keyword = input('keyword');//关键字
        $cate = input('cate/d');//类型
        $layct = input('layct');//楼层
        $Drawing = new Drawing();
        $Config = new Config();
        $count = $Drawing->drawingListCount($keyword,$cate,$layct);
        if (input('?table')) {//是否表格请求
            $result['data'] = $Drawing->drawingList($keyword,$cate,$layct);
            $result['count'] = ceil($count / $this->after_limit);
            return json($result);
        }
        return view('drawingList',[
            'keyword'   => $keyword,
            'count'     => $count,
            'cate'      => $cate,
            'cateList'  => $Config->getConfigTypeList($DrawingConfigurationParameter['cate']),
            'DrawingProgramme'  => $Config->getConfigTypeListArray($DrawingConfigurationParameter['no2']),
            'layct'     => $layct,
            'title'     =>  '图纸列表',
        ]);
    }

    //表格图纸列表
    public function drawingTableList(){
        $DrawingConfigurationParameter = config("DrawingConfigurationParameter");
        $keyword = input('keyword');//关键字
        $cate = input('cate/d');//类型
        $layct = input('layct');//楼层
        $Drawing = new Drawing();
        $Config = new Config();
        if (input('?table')) {//是否表格请求
            $result["code"] = 0;
            $result['data'] = $Drawing->drawingList($keyword,$cate,$layct);
            $result['count'] = $Drawing->drawingListCount($keyword,$cate,$layct);
            return json($result);
        }
        return view('drawingTableList',[
            'keyword'   => $keyword,
            'cate'      => $cate,
            'cateList'  => $Config->getConfigTypeList($DrawingConfigurationParameter['cate']),
            'DrawingProgramme'  => $Config->getConfigTypeListArray($DrawingConfigurationParameter['no2']),
            'layct'     => $layct,
            'title'     =>  '图纸列表',
        ]);
    }

    //添加编辑图纸
    public function drawingAdd(){
        $drawing_id = input("drawing_id/d",0);
        $Drawing = new Drawing();
        if(request()->isPost()){//发布图纸
            $data = input("post.");
            $msg = $Drawing->checkData($data,[
                ["no", "require", "图纸编号不能为空"],
                ["no2", "require", "图纸方案不能为空"],
                ["topic", "require", "图纸标题不能为空"],
                ["cover", "require", "图纸封面不能为空"],
                ["price", "require", "图纸价格不能为空"],
                ["struct", "require", "图纸框架架构不能为空"],
                ["style", "require", "图纸风格不能为空"],
                ["layct", "require", "图纸层数不能为空"],
                ["text_content", "require", "图纸正文内容不能为空"],
                ["substation_id", "require", "请选择发布网站"],
            ]);
            if ($msg === true) {
                if($Drawing->checkFieldOnly("topic",$data["topic"],"drawing_id",$drawing_id)){
                    $result["code"] = 1;
                    $result["msg"] = "图纸标题已存在";
                }else{
                    if($Drawing->checkNO($data["no"],$data["no2"],$drawing_id)){
                        $result["code"] = 1;
                        $result["msg"] = "该编号的图纸已存在改方案！";
                    }else{
                        //验证权限
                        if($Drawing->checkSave($drawing_id,$data["substation_id"])) {
                            $data["drawing_atlas"] = !empty($data["drawing_atlas"]) ? json_encode($data["drawing_atlas"]) : json_encode([]);
                            $data["attrs"] = !empty($data["attrs"]) ? ArrayToStr($data["attrs"]) : "";
                            if ($Drawing->mySave($data, "drawing_id", $drawing_id)) {
                                if(empty($drawing_id)){//添加时候触发
                                    $this->drawingFileMovement($Drawing->getLastInsID());
                                }
                                $result["code"] = 0;
                                $result["msg"] = "操作成功!";
                            } else {
                                $result["code"] = 10000;
                                $result["msg"] = "操作失败！";
                            }
                        }else{
                            $result["code"] = 20000;
                            $result["msg"] = "没有权限操作！";
                        }
                    }
                }
            }else{
                $result["code"] = 1;
                $result["msg"] = $msg;
            }
        }else{//发布之前准备
            if(!empty($drawing_id)) {
                $dataInfo = $Drawing->dataInfo("drawing_id",$drawing_id);//获取库图纸信息
                $this->assign("dataInfo", $dataInfo);
            }
            $Config = new Config();
            //循环获取图纸配置
            foreach (config("DrawingConfigurationParameter") as $key=>$val){
                $this->assign($val, $Config->getConfigTypeList($val));
            }
            $this->assign("DrawingAtlasClassification", $Config->getConfigTypeList("DrawingAtlasClassification"));
            $Substation = new Substation();//分站类
            $userSubstationList = $Substation->userList();//获取分站集合
            $this->assign('userSubstationList',$userSubstationList);
        }
        return !empty($result) ? json($result) : view('drawingAdd',[
            'title'     =>  '添加编辑图纸',
            'RadioIs'   =>  config("IsNoRadio"),//获取Radio配置
            'ueditor'   =>  true,
        ]);
    }

    //删除图纸
    public function drawingDel(){
        $drawing_id = input("drawing_id/d",0);
        $Drawing = new Drawing();
        if(!empty($drawing_id)){
            if($Drawing->checkSave($drawing_id,0)) {
                if ($Drawing->del("drawing_id", $drawing_id, true)) {
                    $result["code"] = 0;
                    $result["msg"] = "操作成功!";
                    $result["url"] = url("Drawings/drawingList");
                } else {
                    $result["code"] = 10000;
                    $result["msg"] = "操作失败！";
                }
            }else{
                $result["code"] = 20000;
                $result["msg"] = "没有权限操作！";
            }
        }else{
            $result["code"] = 1;
            $result["msg"] = "drawing_id，参数为空!";
        }
        return json($result);
    }

    //上传图纸图片
    public function drawingUploadImg(){
        $drawing_id = input("drawing_id");//获取图纸ID
        $type = input("type");//上传类型
        \think\Config::load(APP_PATH.'extra/upload.php');//加载上传配置文件
        $UploadFileConfig = \think\Config::get("UploadFileConfig");//获取配置
        if(!empty($UploadFileConfig[$type])) {//验证上传类型是否存在
            if(!empty($drawing_id)) {
                $Drawing = new Drawing();
                $drawingInfo = $Drawing->PkInfo($drawing_id);
                $UploadFileConfig[$type]["path"] .= $drawingInfo["substation_id"] . "/" . $drawingInfo["no"] . "_" . $drawingInfo["no2"] . ($type == "DrawingCover" ? config("thumbnail") : config("atlas")) . "/";//添加图纸文件夹名称
            }else{
                $UploadFileConfig[$type]["path"] .= "tmp".($type == "CaseThumbnail" ? config("thumbnail") : config("atlas"))."/";//添加图纸文件夹名称
            }
            $data = ["", "array", $UploadFileConfig[$type],[$UploadFileConfig[$type]["width"],$UploadFileConfig[$type]["height"]]];
            if($type == "DrawingAtlas"){//图集上传需要打水印
                $data[] = true;
            }
            $rs = action('FileOperation/uploadImg', $data);//上传图片
            $result = $rs;
        }else{
            $result["code"] = 1;
            $result["msg"] = "上传类型不存在!";
        }
        return json($result);
    }

    //添加完新图纸移动图纸
    private function drawingFileMovement($drawing_id){

        $data = [];//新数组组合

        \think\Config::load(APP_PATH.'extra/upload.php');//加载上传配置文件
        $UploadFileConfig = \think\Config::get("UploadFileConfig");//获取配置

        $Drawing = new Drawing();
        $drawingInfo = $Drawing->PkInfo($drawing_id);

        $FileOperation = new FileOperation();

        //缩略图移动
        if(!empty($drawingInfo["cover"])){
            //是否是在tem文件夹
            if(strpos($drawingInfo["cover"],'/tmp/') !== false) {
                //获取文件名
                $file_name = substr($drawingInfo["cover"], strrpos($drawingInfo["cover"], "/"));
                //设置新文件地址
                $new_file = "/" . $UploadFileConfig["DrawingAtlas"]["path"] . $drawingInfo["substation_id"] . "/" . $drawingInfo["no"] . "_" . $drawingInfo["no2"] . config("thumbnail") . "/" . date("Ymd") . $file_name;
                $data["cover"] = $new_file;//赋值缩略图地址
                $FileOperation->movementFile("." . $drawingInfo["cover"], "." . $new_file);
            }
        }

        //图集移动
        if(!empty($drawingInfo["drawing_atlas"])){
            $drawing_atlas = $drawingInfo["drawing_atlas"];
            if(!empty($drawing_atlas)) {//图集是否为空
                $data["drawing_atlas"] = $drawing_atlas;//赋值数组
                //遍历图集
                foreach ($drawing_atlas as $key => $val) {
                    //图集数组是否为空
                    if(!empty($val["data"])){
                        foreach ($val["data"] as $d_key=>$d_val){
                            //是否是在tem文件夹
                            if(strpos($d_val["url"],'/tmp/') !== false) {
                                //获取文件名
                                $file_name = substr($d_val["url"], strrpos($d_val["url"], "/"));
                                //设置新文件地址
                                $new_file = "/" . $UploadFileConfig["DrawingAtlas"]["path"] . $drawingInfo["substation_id"] . "/" . $drawingInfo["no"] . "_" . $drawingInfo["no2"] . config("atlas") . "/" . date("Ymd") . $file_name;
                                $drawing_atlas[$key]["data"][$d_key]["url"] = $new_file;//赋值缩略图地址
                                $FileOperation->movementFile("." . $d_val["url"], "." . $new_file);
                            }
                        }
                    }
                }
                $data["drawing_atlas"] = json_encode($drawing_atlas);//转为json
            }
        }
        if(!empty($data)) {
            $data["substation_id"] = $drawingInfo["substation_id"];
            $data["attrs"] = $drawingInfo["attrs"];
            $Drawing->mySave($data, "drawing_id", $drawing_id);
        }
    }
}
